package com.geekaca.web.work;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet(urlPatterns = "/register")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        System.out.println();
        System.out.println("======register=====");
        String username = req.getParameter("username");
        System.out.println("username: " + username);

        String password = req.getParameter("password");
        System.out.println("password: " + password);

        String repassword = req.getParameter("repassword");
        System.out.println("repassword: " + repassword);

        String gender = req.getParameter("gender");
        System.out.println("性别: " + gender);

        String[] hobbies = req.getParameterValues("hobby");
        if (hobbies != null) {
            for (int i = 0; i < hobbies.length; i++) {
                System.out.println("hobbie: " + hobbies[i]);
            }
        }

        String desc = req.getParameter("desc");
        System.out.println("个人简介: " + desc);

        String city = req.getParameter("city");
        System.out.println("选择的城市为: " + city);

        if (username.trim() != null && password.trim() != null && password.equals(repassword)) {
            System.out.println("注册成功");
        } else {
            System.out.println("注册失败,用户名为空或两次密码输入不一致...");
        }

    }
}
